﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UofCASE.AgileProductLinerDSL.Nant.Tasks.Models;

namespace APLDTests.NantTests
{
    [TestClass]
    public class EmptyCompositeEnumerator
    {
        CompositeEnumerator<int> iter;

        [TestInitialize]
        public void setup()
        {
            IList<IEnumerable<int>> composite = new List<IEnumerable<int>>();
            iter = new CompositeEnumerator<int>(composite.GetEnumerator() as IEnumerator<IEnumerable<int>>);
        }

        [TestMethod]
        public void CurrentIsNull()
        {
            Assert.AreEqual(default(int), iter.Current);
        }

        [TestMethod]
        public void MoveNextFails()
        {
            Assert.IsFalse(iter.MoveNext());
        }

        [TestMethod]
        public void ResetLeavesStateUnChanged()
        {

        }
    
    }

    [TestClass]
    public class CompositeEnumeratorWithEmptyChild
    {
        CompositeEnumerator<int> iter;

        [TestInitialize]
        public void setup()
        {
            IList<int> ints1 = new List<int>();
            IList<IEnumerable<int>> composite = new List<IEnumerable<int>>();
            composite.Add(ints1);
            iter = new CompositeEnumerator<int>(composite.GetEnumerator());
        }
    
        [TestMethod]
        public void CurrentIsNull()
        {
            Assert.AreEqual(default(int), iter.Current);
        }

        [TestMethod]
        public void MoveNextFails()
        {
            Assert.IsFalse(iter.MoveNext());
        }

        [TestMethod]
        public void ResetLeavesStateUnChanged()
        {

        }

    }

    [TestClass]
    public class CompositeEnumeratorWithNonEmptyChild
    {
        CompositeEnumerator<int> iter;

        [TestInitialize]
        public void setup()
        {
            IList<int> ints1 = new List<int>();
            ints1.Add(1);
            ints1.Add(2);
            IList<IEnumerable<int>> composite = new List<IEnumerable<int>>();
            composite.Add(ints1);
            iter = new CompositeEnumerator<int>(composite.GetEnumerator());
        }

        [TestMethod]
        public void CurrentIsNull()
        {
            Assert.AreEqual(default(int), iter.Current);
        }

        [TestMethod]
        public void MoveNextSucceedsMakingCurrentOne()
        {
            Assert.IsTrue(iter.MoveNext());
            Assert.AreEqual(1, iter.Current);
        }

        [TestMethod]
        public void ResetLeavesStateUnChanged()
        {

        }
    
    }

    [TestClass]
    public class CompositeEnumeratorAtEndOfFirstChild
    {
        CompositeEnumerator<int> iter;

        [TestInitialize]
        public void setup()
        {
            IList<int> ints1 = new List<int>();
            ints1.Add(1);
            ints1.Add(2);
            IList<int> ints2 = new List<int>();
            ints2.Add(3);
            ints2.Add(4);
            IList<IEnumerable<int>> composite = new List<IEnumerable<int>>();
            composite.Add(ints1);
            composite.Add(ints2);
            iter = new CompositeEnumerator<int>(composite.GetEnumerator());
            Assert.IsTrue(iter.MoveNext());
            Assert.IsTrue(iter.MoveNext());
        }

        [TestMethod]
        public void CurrentIsTwo()
        {
            Assert.AreEqual(2, iter.Current);
        }

        [TestMethod]
        public void MoveNextSucceedsMakingCurrentThree()
        {
            Assert.IsTrue(iter.MoveNext());
            Assert.AreEqual(3, iter.Current);
        }

        [TestMethod]
        public void ResetRestartsIter()
        {

        }
    
    }

    [TestClass]
    public class CompositeEnumeratorAtEndOfLastChild
    {
        CompositeEnumerator<int> iter;

        [TestInitialize]
        public void setup()
        {
            IList<int> ints1 = new List<int>();
            ints1.Add(1);
            ints1.Add(2);
            IList<int> ints2 = new List<int>();
            ints2.Add(3);
            ints2.Add(4);
            IList<IEnumerable<int>> composite = new List<IEnumerable<int>>();
            composite.Add(ints1);
            composite.Add(ints2);
            iter = new CompositeEnumerator<int>(composite.GetEnumerator());
            Assert.IsTrue(iter.MoveNext());
            Assert.IsTrue(iter.MoveNext());
            Assert.IsTrue(iter.MoveNext());
            Assert.IsTrue(iter.MoveNext());
        }

        [TestMethod]
        public void CurrentIsFour()
        {
            Assert.AreEqual(4, iter.Current);
        }

        [TestMethod]
        public void MoveNextFails()
        {
            Assert.IsFalse(iter.MoveNext());
        }

        [TestMethod]
        public void ResetsTheIter()
        {

        }
    

    }
}
